//
//  QYFourViewController.m
//  QYBaseProject
//
//  Created by Dxc_iOS on 2018/10/12.
//  Copyright © 2018 代星创. All rights reserved.
//

#import "QYFourViewController.h"
#import <SuperPlayer/SuperPlayer.h>
#import <Masonry.h>
@interface QYFourViewController ()<SuperPlayerDelegate>
/** 播放器View的父视图*/
@property (nonatomic) UIView *playerFatherView;
@property (strong, nonatomic) SuperPlayerView *playerView;
/** 离开页面时候是否在播放 */
@property (nonatomic, assign) BOOL isPlaying;

@property UIButton *vodBtn;    // 点播标签
@property UIButton *liveBtn;   // 直播标签
@end

@implementation QYFourViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.playerFatherView = [[UIView alloc] init];
    self.playerFatherView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.playerFatherView];
    [self.playerFatherView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        } else {
            make.top.mas_equalTo(20+self.navigationController.navigationBar.bounds.size.height);
        }
        make.leading.trailing.mas_equalTo(0);
        // 这里宽高比16：9,可自定义宽高比
        make.height.mas_equalTo(self.playerFatherView.mas_width).multipliedBy(9.0f/16.0f);
    }];
    self.playerView.fatherView = self.playerFatherView;
    
    
//    http://5815.liveplay.myqcloud.com/live/5815_89aad37e06ff11e892905cb9018cf0d4.flv
    
    SuperPlayerModel *playerModel = [[SuperPlayerModel alloc] init];
    // 设置播放地址，直播、点播都可以
    playerModel.videoURL = @"http://5815.liveplay.myqcloud.com/live/5815_89aad37e06ff11e892905cb9018cf0d4_550.flv";
    // 开始播放
    [_playerView playWithModel:playerModel];
    
    
    
    self.vodBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.vodBtn];
    [self.vodBtn setTitle:@"点播列表" forState:UIControlStateNormal];
    [self.vodBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.vodBtn setTitleColor:[UIColor lightTextColor] forState:UIControlStateNormal];
    [self.vodBtn addTarget:self action:@selector(clickVodList:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.liveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.liveBtn];
    [self.liveBtn setTitle:@"直播列表" forState:UIControlStateNormal];
    [self.liveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.liveBtn setTitleColor:[UIColor lightTextColor] forState:UIControlStateNormal];
    [self.liveBtn addTarget:self action:@selector(clickLiveList:) forControlEvents:UIControlEventTouchUpInside];
    [self.vodBtn setSelected:YES];
    
    CGFloat btnWidth = self.vodBtn.titleLabel.attributedText.size.width;
    [self.vodBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.playerFatherView.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(-btnWidth);
    }];
    [self.liveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.playerFatherView.mas_bottom).offset(10);
        make.centerX.mas_equalTo(self.view.mas_centerX).mas_offset(btnWidth);
    }];
    
    
    
    
}

// 返回值要必须为NO
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    // 这里设置横竖屏不同颜色的statusbar
    // if (SuperPlayerShared.isLandscape) {
    //    return UIStatusBarStyleDefault;
    // }
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden {
    return self.playerView.isFullScreen;
}

#pragma mark - SuperPlayerDelegate

- (void)superPlayerBackAction:(SuperPlayerView *)player {
//    [self backClick];
}
#pragma mark - Getter

- (SuperPlayerView *)playerView {
    if (!_playerView) {
        _playerView = [[SuperPlayerView alloc] init];
        _playerView.fatherView = _playerFatherView;
        // 设置代理
        _playerView.delegate = self;
//        [self setupDanmakuData];
    }
    return _playerView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
